package com.skyz.wrap.utils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class DateFormatUtils {
    private static final String DATE_FORMAT_PATTERN_YMD = "yyyy-MM-dd";
    private static final String DATE_FORMAT_PATTERN_YMD_HM = "yyyy-MM-dd HH:mm";
    private static final String DATE_FORMAT_PATTERN_HS = "mm:ss";

    public DateFormatUtils() {
    }

    public static String long2Str(long timestamp, boolean isPreciseTime) {
        return long2Str(timestamp, getFormatPattern(isPreciseTime));
    }

    public static String long2StrHS(long timestamp) {
        return long2Str(timestamp, "mm:ss");
    }

    private static String long2Str(long timestamp, String pattern) {
        return (new SimpleDateFormat(pattern, Locale.CHINA)).format(new Date(timestamp));
    }

    public static long str2Long(String dateStr, boolean isPreciseTime) {
        return str2Long(dateStr, getFormatPattern(isPreciseTime));
    }

    private static long str2Long(String dateStr, String pattern) {
        try {
            return (new SimpleDateFormat(pattern, Locale.CHINA)).parse(dateStr).getTime();
        } catch (Throwable var3) {
            return 0L;
        }
    }

    private static String getFormatPattern(boolean showSpecificTime) {
        return showSpecificTime ? "yyyy-MM-dd HH:mm" : "yyyy-MM-dd";
    }
}
